<?php
include (dirname(__FILE__).DIRECTORY_SEPARATOR."template.inc");

class ReportTemplate extends Template
{
  function parse($target, $varname, $append = false) {
//  	$v = "<!-- FILTER 0 || 0 -->\r\nlksjdfsdjg";
//	    $reg = "/[ \t]*<!--\s+FILTER (.{0,2}|([^-]..|-[^-].|--[^>]|.{4,})*)\s+-->\s*?\n?(\s*.*?\n?)\s*/sm";
//	    preg_match_all($reg, $v, $m);
//	    		Constants::print_var($m);
//  	
//  	
    if (!is_array($varname)) {
	    $str = $this->subst($varname);
	    $reg = "/[ \t]*<!--\s+FILTER\s+(([^-]|-[^-]|--[^>])+)\s+-->(\s*?\n?(\s*.*?\n?)\s*?\n?)/smi";
	    preg_match_all($reg, $str, $m);
	    $r = true;
	    		//Constants::print_var($str, false);
	    		//Constants::print_var(preg_replace($reg, "", $str), false);
	    		//Constants::print_var($m);
	    if (isset($m[1]) && isset($m[1][0]))
	    {
	    	if ($m[1][0] == "")
	    		$m[1][0] = "false";
		    eval('$r='.$m[1][0].";");
		    $str = preg_replace($reg, "", $str);
	    }
	    if ($r)
	    {
	        if ($append) {
	          $this->set_var($target, $this->get_var($target) . $str);
	        } else {
	          $this->set_var($target, $str);
	        }
	    	parent::parse($target, $varname, $append);
	    }
	    
    } else {
      reset($varname);
      while(list($i, $v) = each($varname)) {
	    	$this->parse($target, $v, $append);
      }
    }
  }
}
?>
